gh-88267: Avoid exporting functions when a static build is used #99888
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In a Python core static build scenario (for example: embedding in Windows), MSVC would export the Python symbols for such application as well.
This commit fixes this behavour allowing the application to not export python modules and remove the automatically generated lib file, wichi shouldn't be generated for an executable.
Modules such as _socket.pyd would be disabled in a static build as the linked environment would differ, therefore I don't think there is any use for having an application specifically export modules.
In case where such behavour would be required, I would suggest adding an extra macro to disable such exports (such as Py_NO_EXPORTS).
This behavour has been tested on Windows MSVC2022, on Linux I don't think GCC would automatically export such functions but I'm not an expert on that topic.
(Fixes #88267)
NOTE: I am aware that pythoncore currently doesn't build properly in static, I used vcpkg's https://github.com/microsoft/vcpkg/blob/master/ports/python3/0002-static-library.patch (updated for Py 3.12) along with some changes to PC/dl_nt.c to allow the python interpreter to properly run, I could send a PR for this changes in case.